package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BizInspectionTemplate;
import com.ruoyi.system.service.IBizInspectionTemplateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 检验方案Controller
 * 
 * @author ruoyi
 * @date 2025-10-29
 */
@RestController
@RequestMapping("/system/template")
public class BizInspectionTemplateController extends BaseController
{
    @Autowired
    private IBizInspectionTemplateService bizInspectionTemplateService;

    /**
     * 查询检验方案列表
     */
    @PreAuthorize("@ss.hasPermi('system:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizInspectionTemplate bizInspectionTemplate)
    {
        startPage();
        List<BizInspectionTemplate> list = bizInspectionTemplateService.selectBizInspectionTemplateList(bizInspectionTemplate);
        return getDataTable(list);
    }

    /**
     * 导出检验方案列表
     */
    @PreAuthorize("@ss.hasPermi('system:template:export')")
    @Log(title = "检验方案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizInspectionTemplate bizInspectionTemplate)
    {
        List<BizInspectionTemplate> list = bizInspectionTemplateService.selectBizInspectionTemplateList(bizInspectionTemplate);
        ExcelUtil<BizInspectionTemplate> util = new ExcelUtil<BizInspectionTemplate>(BizInspectionTemplate.class);
        util.exportExcel(response, list, "检验方案数据");
    }

    /**
     * 获取检验方案详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:template:query')")
    @GetMapping(value = "/{templateId}")
    public AjaxResult getInfo(@PathVariable("templateId") Long templateId)
    {
        return success(bizInspectionTemplateService.selectBizInspectionTemplateByTemplateId(templateId));
    }

    /**
     * 新增检验方案
     */
    @PreAuthorize("@ss.hasPermi('system:template:add')")
    @Log(title = "检验方案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizInspectionTemplate bizInspectionTemplate)
    {
        return toAjax(bizInspectionTemplateService.insertBizInspectionTemplate(bizInspectionTemplate));
    }

    /**
     * 修改检验方案
     */
    @PreAuthorize("@ss.hasPermi('system:template:edit')")
    @Log(title = "检验方案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizInspectionTemplate bizInspectionTemplate)
    {
        return toAjax(bizInspectionTemplateService.updateBizInspectionTemplate(bizInspectionTemplate));
    }

    /**
     * 删除检验方案
     */
    @PreAuthorize("@ss.hasPermi('system:template:remove')")
    @Log(title = "检验方案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{templateIds}")
    public AjaxResult remove(@PathVariable Long[] templateIds)
    {
        return toAjax(bizInspectionTemplateService.deleteBizInspectionTemplateByTemplateIds(templateIds));
    }
}
